﻿using Colorful.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using Colorful.Models;
using MongoDB.Driver;

namespace TestApp
{
    #region MongodbContext
    public class DbContext : MongodbContext
    {
        private IMongoDatabase _db;

        #region 初始化
        public DbContext(string server, string username, string password, string dbName)
            : base(server, username, password, dbName)
        {
            _db = this.Database;
        }
        public DbContext(string connStr, string dbName, string collectionPrefix = "")
            :base(connStr, dbName, collectionPrefix)
        {
            _db = this.Database;
        }
        #endregion

        #region Collections
        /// <summary>
        /// 会员表
        /// </summary>
        public IMongoCollection<Colorful.MemberSystem.Models.Member> Members
        {
            get
            {
                return this.GetCollection<Colorful.MemberSystem.Models.Member>("Members");
            }
        }
        /// <summary>
        /// 报表日程安排
        /// </summary>
        public IMongoCollection<ReportSchedule> ReportSchedules
        {
            get
            {
                return _db.GetCollection<ReportSchedule>("ReportSchedule");
            }
        }
        /// <summary>
        /// 网站访客信息
        /// </summary>
        public IMongoCollection<VisitorRecord> VisitorRecords
        {
            get
            {
                return _db.GetCollection<VisitorRecord>("VisitorRecord");
            }
        }
        /// <summary>
        /// 按UV PV统计
        /// </summary>
        public IMongoCollection<Statistic> Statistics
        {
            get
            {
                return _db.GetCollection<Statistic>("Statistic");
            }
        }
        /// <summary>
        /// 计数器
        /// </summary>
        public IMongoCollection<Counter> Counters
        {
            get
            {
                return _db.GetCollection<Counter>("Counter");
            }
        }
        /// <summary>
        /// 按访问页面统计
        /// </summary>
        public IMongoCollection<StatByPage> StatByPages
        {
            get
            {
                return _db.GetCollection<StatByPage>("StatByPage");
            }
        }
        /// <summary>
        /// 按域名统计
        /// </summary>
        public IMongoCollection<StatByDomain> StatByDomains
        {
            get
            {
                return _db.GetCollection<StatByDomain>("StatByDomain");
            }
        }
        /// <summary>
        /// 按国家统计
        /// </summary>
        public IMongoCollection<StatByCountry> StatByCountries
        {
            get
            {
                return _db.GetCollection<StatByCountry>("StatByCountry");
            }
        }
        /// <summary>
        /// 按地区统计
        /// </summary>
        public IMongoCollection<StatByArea> StatByAreas
        {
            get
            {
                return _db.GetCollection<StatByArea>("StatByArea");
            }
        }
        #endregion
    }
    #endregion
}
